package com.ruoyi.system.service.standard.impl;

import java.util.List;

import com.ruoyi.common.annotation.DataScope;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.standard.StandardIECMapper;
import com.ruoyi.system.domain.standard_relevant.StandardIEC;
import com.ruoyi.system.service.standard.IStandardIECService;

/**
 * IEC 标准结构Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-07-08
 */
@Service
public class StandardIECServiceImpl implements IStandardIECService 
{
    @Autowired
    private StandardIECMapper standardIECMapper;

    /**
     * 查询IEC 标准结构
     * 
     * @param id IEC 标准结构主键
     * @return IEC 标准结构
     */
    @Override
    public StandardIEC selectStandardIECById(Long id)
    {
        return standardIECMapper.selectStandardIECById(id);
    }

    /**
     * 查询IEC 标准结构列表
     * 
     * @param standardIEC IEC 标准结构
     * @return IEC 标准结构
     */
    @Override
    public List<StandardIEC> selectStandardIECList(StandardIEC standardIEC)
    {
        return standardIECMapper.selectStandardIECList(standardIEC);
    }

    /**
     * 新增IEC 标准结构
     * 
     * @param standardIEC IEC 标准结构
     * @return 结果
     */
    @Override
    public int insertStandardIEC(StandardIEC standardIEC)
    {
        return standardIECMapper.insertStandardIEC(standardIEC);
    }

    /**
     * 修改IEC 标准结构
     * 
     * @param standardIEC IEC 标准结构
     * @return 结果
     */
    @Override
    public int updateStandardIEC(StandardIEC standardIEC)
    {
        return standardIECMapper.updateStandardIEC(standardIEC);
    }

    /**
     * 添加或更新IEC 标准结构
     *
     * @param standardIEC IEC 标准结构
     * @return 结果
     */
    @Override
    public int addOrUpdateStandardIEC(StandardIEC standardIEC) {
        // 先检查是否存在该标准
        StandardIEC existing = selectStandardIECByCode(standardIEC.getStandardCode());
        if (existing == null) {
            // 如果不存在，则新增
            return insertStandardIEC(standardIEC);
        } else {
            // 如果存在，则更新
            standardIEC.setId(existing.getId()); // 确保ID正确
            return updateStandardIEC(standardIEC);
        }
    }

    /**
     * 批量删除IEC 标准结构
     * 
     * @param ids 需要删除的IEC 标准结构主键
     * @return 结果
     */
    @Override
    public int deleteStandardIECByIds(Long[] ids)
    {
        return standardIECMapper.deleteStandardIECByIds(ids);
    }

    /**
     * 删除IEC 标准结构信息
     * 
     * @param id IEC 标准结构主键
     * @return 结果
     */
    @Override
    public int deleteStandardIECById(Long id)
    {
        return standardIECMapper.deleteStandardIECById(id);
    }

    /**
     *--------------------------------------------------------
     */

    /**
     * 找到指定的IEC 标准 By Code
     * @param standardCode
     */
    @Override
    public StandardIEC selectStandardIECByCode(String standardCode) {
        return standardIECMapper.selectStandardIECByCode(standardCode);
    }
    /**
     * 删除 IEC by code
     */
    @Override
    public int deleteStandardIECByCode(String standardCode){
        return standardIECMapper.deleteStandardIECByCode(standardCode);
    }
}
